﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UICalendarTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetRowCount()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(6, calendar.RowCount);
        }

        [TestMethod]
        public void ShouldGetColumnCount()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(7, calendar.ColumnCount);
        }

        [TestMethod]
        public void ShouldGetCurrentView()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(0, calendar.CurrentView);
        }

        [TestMethod]
        public void ShouldGetSupportedViews()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(3, calendar.GetSupportedViews().Length);
        }

        [TestMethod]
        public void ShouldGetCanSelectMultiple()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsFalse(calendar.CanSelectMultiple);
        }

        [TestMethod]
        public void ShouldGetIsSelectionRequired()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsFalse(calendar.IsSelectionRequired);
        }

        [TestMethod]
        public void ShouldGetRowOrColumnMajor()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsTrue(calendar.RowOrColumnMajor.HasValue);
            Assert.AreEqual(RowOrColumnMajor.RowMajor, calendar.RowOrColumnMajor.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldSetCurrentView()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            calendar.SetCurrentView(1);
            Assert.AreEqual(1, calendar.CurrentView);
        }

        [TestMethod]
        public void ShouldGetSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(0, calendar.GetSelection().Length);
        }

        [TestMethod]
        public void ShouldGetColumnHeaders()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(7, calendar.GetColumnHeaders().Length);
        }

        [TestMethod]
        public void ShouldGetRowHeaders()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.AreEqual(0, calendar.GetRowHeaders().Length);
        }

        [TestMethod]
        public void ShouldGetHorizontallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsFalse(calendar.HorizontallyScrollable);
        }

        [TestMethod]
        public void ShouldGetHorizontalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsTrue(double.IsNaN(calendar.HorizontalScrollPercent));
        }

        [TestMethod]
        public void ShouldGetHorizontalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsTrue(double.IsNaN(calendar.HorizontalViewSize));
        }

        [TestMethod]
        public void ShouldGetVerticallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsFalse(calendar.VerticallyScrollable);
        }

        [TestMethod]
        public void ShouldGetVerticalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsTrue(double.IsNaN(calendar.VerticalScrollPercent));
        }

        [TestMethod]
        public void ShouldGetVerticalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            UICalendar calendar = datePicker.UICalendar();
            Assert.IsTrue(double.IsNaN(calendar.VerticalViewSize));
        }

        [TestMethod]
        public void ShouldGetAllCalendars()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICustom datePicker = window.UICustom("@AutomationId='datePicker1'");
            datePicker.UIButton("@Name='Show Calendar'").Press();
            List<UICalendar> calendars = datePicker.UICalendars();
            Assert.AreEqual(1, calendars.Count);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}